package com.lyf.boot.modules.system.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.lyf.boot.core.model.R;
import com.lyf.boot.modules.system.service.IFileService;
import lombok.RequiredArgsConstructor;
import org.dromara.x.file.storage.core.FileInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件管理
 * @author Luyufan
 * @date 2023/8/15 14:07
 */
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileController {

    private final IFileService fileService;

    /**
     * 文件上传
     * @param file 文件
     * @param path 路径
     * @param platform 平台
     * @return 上传结果
     */
    @PostMapping("/upload")
    @SaIgnore
    public R<FileInfo> uploadFile(@RequestParam(value = "file") MultipartFile file,
                                  @RequestParam(value = "path", required = false) String path,
                                  @RequestParam(value = "platform", required = false) String platform){
        return R.ok(fileService.upload(file, path, platform));
    }

//    @GetMapping("/sseConnect/{md5}")
//    @SaIgnore
//    public SseEmitter connect(@PathVariable String md5){
//        return SSEServer.connect(md5);
//    }

}
